<?php
session_start();

require("includes/funciones.inc.php");
require("includes/constants.php");

$DB = NewADOConnection('mysqlt');
$DB->Connect();
$DB->Execute("SET NAMES utf8;");
//$DB->debug=true;

//LOGIN
if(!empty($_POST['usuario']))
{
	$mcrypt = new MCrypt();
	$encryptedPass = $mcrypt->encrypt($_REQUEST["password"]);
			
	$strSQL = "SELECT * FROM usuarios WHERE usuario = '".$_REQUEST['usuario']."' AND password = '".$encryptedPass."'";
	
	$rsUsuario = $DB->Execute($strSQL); 
	if (!$rsUsuario->EOF)
	{
		$_SESSION['idUsuario'] = $rsUsuario->fields("idUsuario");
		$_SESSION['nombreUsuario'] = $rsUsuario->fields("usuario");
		$_SESSION['nombreCompleto'] = $rsUsuario->fields("nombreCompleto");
		$_SESSION['idTipoUsuario'] = $rsUsuario->fields("idTipoUsuario");
			
		Header("Location: principal.php");
		exit();
	}
}
?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Insumos Pompeya">
    <meta name="author" content="Federico Pisarello">

    <title>Insumos Pompeya</title>

    <!-- Bootstrap core CSS -->
    <link href="css/bootstrap.css" rel="stylesheet">
    <link href="css/css.css" rel="stylesheet">
        
    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
 	<![endif]-->
</head>

<body>
    <div class="container">
    	<div class="jumbotron">
	    	<h2 class="frmLogin-heading">Viras Pompeya S.A. - Login</h2>
			<form class="frmLogin" id="frmLogin" name="frmLogin" method="post" action="" onsubmit="return $_validateLoginForm();">
	        	<input type="text" id="usuario" name="usuario" class="form-control" placeholder="Usuario" autofocus>
	        	<input type="password" id="password" name="password" class="form-control" placeholder="Password">
	        	<button class="btn btn-lg btn-primary btn-block" type="submit">Ingresar</button>
	      	</form>
		</div>
	      
	    <div class="footer">
			<p>Copyright &copy; 2013 - Ing. Federico N. Pisarello</p>
	    </div>
    </div>

	<script src="js/jquery-1.9.1.js"></script>
    <script src="js/jquery-ui.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    
    <!-- Form Script -->
	<script type="text/javascript" src="js/login.js"></script>
  	<script type="text/javascript" src="js/utils.js"></script>
	
  	<!-- Iniciar Formulario -->
  	<script type='text/javascript'>
	$(document).ready(
		function() {
			<?php if (!empty($_POST['usuario']) && $rsUsuario->EOF) { ?>
				$_showMessage('ERR', 'ERROR', 'Nombre de Usuario o Clave Incorrecta');
			<?php } ?>
	});
	</script>
    
</body>
  
<!-- Global Message -->
<div id="globalMess"> 
	<div class="img"></div>
	<div id="globalMessImgClose" class="imgClose"></div>
	<div id="tituloMess" class="msgTitulo">TITULO</div>
	<p id="textoMess" class="msgTexto">MENSAJE</p>
</div>

</html>
